package com.gnerv.sylvanas.business.manage.controller;

import com.gnerv.sylvanas.framework.common.model.RestResult;
import com.gnerv.sylvanas.business.manage.logic.RoleLogicService;
import com.gnerv.sylvanas.business.manage.model.dto.RoleAccountDTO;
import com.gnerv.sylvanas.business.manage.model.dto.RoleApiDTO;
import com.gnerv.sylvanas.business.manage.model.dto.RoleCreateDTO;
import com.gnerv.sylvanas.business.manage.model.dto.RoleDTO;
import com.gnerv.sylvanas.business.manage.model.dto.RoleUpdateDTO;
import com.gnerv.sylvanas.business.manage.model.dto.RoleViewDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping(value = "/api/manage/role")
public class RoleController {

    private final RoleLogicService roleLogicService;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody RoleCreateDTO roleCreateDTO) {
        return roleLogicService.create(roleCreateDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return roleLogicService.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody RoleUpdateDTO roleUpdateDTO) {
        return roleLogicService.updateByUkId(roleUpdateDTO);
    }

    @PutMapping(value = "/bind/account")
    public RestResult<Void> bindAccount(@RequestBody RoleAccountDTO roleAccountDTO) {
        return roleLogicService.bindAccount(roleAccountDTO);
    }

    @PutMapping(value = "/bind/api")
    public RestResult<Void> bindApi(@RequestBody RoleApiDTO roleApiDTO) {
        return roleLogicService.bindApi(roleApiDTO);
    }

    @PutMapping(value = "/bind/view")
    public RestResult<Void> bindView(@RequestBody RoleViewDTO roleViewDTO) {
        return roleLogicService.bindView(roleViewDTO);
    }

    @GetMapping(value = "")
    public RestResult<RoleDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return roleLogicService.selectByUkId(ukId);
    }

    @GetMapping(value = "/list")
    public RestResult<List<RoleDTO>> selectListByName(@RequestParam(required = false, value = "name") String name) {
        return roleLogicService.selectListByName(name);
    }

}
